package day02;

import utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/*
    批处理测试
*/
public class BatchProcess {
    public static void main(String[] args) {
        Connection con;
        PreparedStatement ps;
        try{
            con = JDBCUtils.getConnection();
            String sql = "insert into demo values(null,?,?)";
            ps = con.prepareStatement(sql);
            for (int i = 0; i < 10; i++) {
                ps.setString(1,"user" + (i+1));
                ps.setString(2,"" + (123456+i));
                ps.addBatch();
            }
            ps.executeBatch();
            ps.clearBatch();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        JDBCUtils.close(con,ps);
    }
}
